package com.qhhc.service.impl;

import com.qhhc.entity.CarEn;
import com.qhhc.mapper.CarEnMapper;
import com.qhhc.service.CarEnService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class CarEnServiceImpl implements CarEnService {

    @Autowired
    private CarEnMapper carEnMapper;

    @Override
    public List<CarEn> getAllCars() {
        return carEnMapper.selectAll();
    }

    @Override
    public List<CarEn> getPopularCars() {
        return carEnMapper.selectPopularCars();
    }

    @Override
    public CarEn getCarById(Long carId) {
        System.out.println("根据id查找车"+carId);
        CarEn carEn = carEnMapper.selectById(carId);
        System.out.println(carEn.toString());
        return carEn;
    }

    @Override
    @Transactional
    public boolean addCar(CarEn car) {
        return carEnMapper.insert(car) > 0;
    }

    @Override
    @Transactional
    public boolean updateCar(CarEn car) {
        return carEnMapper.update(car) > 0;
    }

    @Override
    @Transactional
    public boolean deleteCar(Long carId) {
        return carEnMapper.deleteById(carId) > 0;
    }

    @Override
    @Transactional
    public boolean deleteCars(List<Long> carIds) {
        return carEnMapper.deleteByIds(carIds) > 0;
    }

    @Override
    public List<CarEn> getCarsByCondition(CarEn car) {
        return carEnMapper.selectByCondition(car);
    }
} 